import axios from 'axios'
import * as actionTypes from './actionTypes'

const initTopList = (data) => ({
  type: actionTypes.INIT_TOP_LIST,
  data
})

const loadMoreList = (data) => ({
  type: actionTypes.LOAD_MORE_LIST,
  data
})

export const getInitTopList = () => {
  return async (dispatch) => {
    const { data: res } = await axios.get(
      '/api/homeList.json'
    )
    if (res.status !== 200) return
    // console.log(res.data)
    dispatch(initTopList(res.data))
  }
}

export const getLoadMoreList = () => {
  return async (dispatch) => {
    const { data: res } = await axios.get(
      '/api/loadmoreList.json'
    )
    if (res.status !== 200) return
    // console.log(res.data)
    dispatch(loadMoreList(res.data))
  }
}

export const changeScroll = (flag) => ({
  type: actionTypes.CHANGE_SCROLL,
  flag
})